/**
 * Created by WLG on 2018/11/9.
 */
let serverConfig = require('../config/serverConfig');
const redisDB = require('../lib/redisManage');
class BaseHandler {
    static async emitMsg(io,socketId,eventName,msg){
        await io.of(serverConfig.socketNameSpace).sockets[socketId].emit(eventName,msg);
    }

    /**
     * 是否存在 SocketMsgId
     * @param id
     * @returns {Promise.<boolean>}
     */
    static async checkSocketMsgIdExistAndCacheIt(id){
        let result = false;
        let key = "SocketMsgID:"+id;
        let tempID = await redisDB.get(key);
        if(tempID){
            result = true;
        }else{
            await redisDB.set(key, id, serverConfig.socketMsgIDCacheTime);
        }
        return result;
    }
}
module["exports"] = BaseHandler;